Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add other client extensions #637

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add other client extensions #637

wants to merge 4 commits into from

Conversation

mtmk
Copy link
Collaborator

@mtmk mtmk commented Sep 23, 2024

Refactor to use interfaces for enhanced flexibility and testability across various components like NatsJSContext and NatsConnection. Added new extension methods to easily create contexts for Object Store, Key-Value Store, and Services on NATS client and connection instances.

await using var client = new NatsClient();

// Use KeyValueStore extension method by referencing NATS.Client.KeyValueStore package
INatsKVContext kv = client.CreateKeyValueStoreContext();

// Use ObjectStore extension method by referencing NATS.Client.ObjectStore package
INatsObjContext obj = client.CreateObjectStoreContext();

// Use Services extension method by referencing NATS.Client.Services package
INatsSvcContext svc = client.CreateServicesContext();

Refactor to use interfaces for enhanced flexibility and testability across various components like NatsJSContext and NatsConnection. Added new extension methods to easily create contexts for Object Store, Key-Value Store, and Services on NATS client and connection instances.
Updated INatsObjStore, INatsKVContext, and INatsSvcContext interfaces to include public `Context` properties. This change ensures consistent access to the underlying context objects across various components.
@mtmk mtmk changed the title Other client extensions Add other client extensions Sep 23, 2024
@rickdotnet
Copy link
Collaborator

🙌 looking forward to this!

Copy link
Collaborator

@rickdotnet rickdotnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. All comments are thought provoking.

/// <summary>
/// Provides access to the JetStream context associated with the Key-Value Store operations.
/// </summary>
INatsJSContext Context { get; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, but wondering what you think about folks using code like

var context = client.CreateKeyValueStoreContext();
...
var jsContext = context.Context;

I don't mind it, but the thought came to mind and figured I'd mention it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about JetStreamContext or just JetStream?

var context = client.CreateKeyValueStoreContext();
...
var jsContext = context.JetStreamContext;
...
var jsContext = context.JetStream;

public NatsKVContext(NatsJSContext context) => _context = context;
public NatsKVContext(INatsJSContext context) => Context = context;

/// <inheritdoc />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My OCD thanks you for this. Prob don't need to, but could do the rest while you're here. ;) Might make sense as a separate maintenance PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean using the new type constructors (or whatever they're called)?

/// <param name="client">The NATS client instance.</param>
/// <returns>An instance of <see cref="INatsKVContext"/> which can be used to interact with the Key-Value Store.</returns>
public static INatsKVContext CreateKeyValueStoreContext(this INatsClient client)
=> CreateKeyValueStoreContext(client.Connection);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to chain these to the JS extensions?

public static INatsKVContext CreateKeyValueStoreContext(this INatsClient client)
    => CreateKeyValueStoreContext(client.CreateJetStreamContext());

public static INatsKVContext CreateKeyValueStoreContext(this INatsConnection connection)
    => CreateKeyValueStoreContext(connection.CreateJetStreamContext());

Copy link
Collaborator Author

@mtmk mtmk Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense 💯 done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

INatsClient Services API extensions INatsClient Object Store API extensions INatsClient KV API extensions
2 participants